/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = 'regional';
  @endpointMap = {
    cn-qingdao = 'wafopenapi.cn-hangzhou.aliyuncs.com',
    cn-beijing = 'wafopenapi.cn-hangzhou.aliyuncs.com',
    cn-chengdu = 'wafopenapi.cn-hangzhou.aliyuncs.com',
    cn-zhangjiakou = 'wafopenapi.cn-hangzhou.aliyuncs.com',
    cn-huhehaote = 'wafopenapi.cn-hangzhou.aliyuncs.com',
    cn-hangzhou = 'wafopenapi.cn-hangzhou.aliyuncs.com',
    cn-shanghai = 'wafopenapi.cn-hangzhou.aliyuncs.com',
    cn-shenzhen = 'wafopenapi.cn-hangzhou.aliyuncs.com',
    cn-heyuan = 'wafopenapi.cn-hangzhou.aliyuncs.com',
    cn-wulanchabu = 'wafopenapi.cn-hangzhou.aliyuncs.com',
    cn-hongkong = 'wafopenapi.ap-southeast-1.aliyuncs.com',
    ap-southeast-1 = 'wafopenapi.ap-southeast-1.aliyuncs.com',
    ap-southeast-2 = 'wafopenapi.ap-southeast-1.aliyuncs.com',
    ap-southeast-3 = 'wafopenapi.ap-southeast-1.aliyuncs.com',
    ap-southeast-5 = 'wafopenapi.ap-southeast-1.aliyuncs.com',
    eu-west-1 = 'wafopenapi.ap-southeast-1.aliyuncs.com',
    us-west-1 = 'wafopenapi.ap-southeast-1.aliyuncs.com',
    us-east-1 = 'wafopenapi.ap-southeast-1.aliyuncs.com',
    eu-central-1 = 'wafopenapi.ap-southeast-1.aliyuncs.com',
    me-east-1 = 'wafopenapi.ap-southeast-1.aliyuncs.com',
    ap-south-1 = 'wafopenapi.ap-southeast-1.aliyuncs.com',
    cn-shanghai-finance-1 = 'wafopenapi.cn-hangzhou.aliyuncs.com',
    cn-shenzhen-finance-1 = 'wafopenapi.cn-hangzhou.aliyuncs.com',
    cn-north-2-gov-1 = 'wafopenapi.cn-hangzhou.aliyuncs.com',
  };

  checkConfig(config);
  @endpoint = getEndpoint('waf-openapi', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model CreateInstanceRequest {
  autoRenewDuration?: int32(name='AutoRenewDuration'),
  clientToken?: string(name='ClientToken'),
  duration?: int32(name='Duration'),
  extBandwidth?: int32(name='ExtBandwidth'),
  extDomainPackage?: int32(name='ExtDomainPackage'),
  isAutoRenew?: boolean(name='IsAutoRenew'),
  ownerId?: long(name='OwnerId'),
  packageCode?: string(name='PackageCode'),
  pricingCycle?: string(name='PricingCycle'),
}

model CreateInstanceResponseBody = {
  instanceId?: string(name='InstanceId'),
  orderId?: string(name='OrderId'),
  requestId?: string(name='RequestId'),
}

model CreateInstanceResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: CreateInstanceResponseBody(name='body'),
}

async function createInstanceWithOptions(request: CreateInstanceRequest, runtime: Util.RuntimeOptions): CreateInstanceResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.autoRenewDuration)) {
    query['AutoRenewDuration'] = request.autoRenewDuration;
  }
  if (!Util.isUnset(request.clientToken)) {
    query['ClientToken'] = request.clientToken;
  }
  if (!Util.isUnset(request.duration)) {
    query['Duration'] = request.duration;
  }
  if (!Util.isUnset(request.extBandwidth)) {
    query['ExtBandwidth'] = request.extBandwidth;
  }
  if (!Util.isUnset(request.extDomainPackage)) {
    query['ExtDomainPackage'] = request.extDomainPackage;
  }
  if (!Util.isUnset(request.isAutoRenew)) {
    query['IsAutoRenew'] = request.isAutoRenew;
  }
  if (!Util.isUnset(request.ownerId)) {
    query['OwnerId'] = request.ownerId;
  }
  if (!Util.isUnset(request.packageCode)) {
    query['PackageCode'] = request.packageCode;
  }
  if (!Util.isUnset(request.pricingCycle)) {
    query['PricingCycle'] = request.pricingCycle;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'CreateInstance',
    version = '2016-11-11',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function createInstance(request: CreateInstanceRequest): CreateInstanceResponse {
  var runtime = new Util.RuntimeOptions{};
  return createInstanceWithOptions(request, runtime);
}

model ReleaseInstanceRequest {
  instanceId?: string(name='InstanceId'),
  ownerId?: long(name='OwnerId'),
}

model ReleaseInstanceResponseBody = {
  requestId?: string(name='RequestId'),
}

model ReleaseInstanceResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: ReleaseInstanceResponseBody(name='body'),
}

async function releaseInstanceWithOptions(request: ReleaseInstanceRequest, runtime: Util.RuntimeOptions): ReleaseInstanceResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.instanceId)) {
    query['InstanceId'] = request.instanceId;
  }
  if (!Util.isUnset(request.ownerId)) {
    query['OwnerId'] = request.ownerId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ReleaseInstance',
    version = '2016-11-11',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function releaseInstance(request: ReleaseInstanceRequest): ReleaseInstanceResponse {
  var runtime = new Util.RuntimeOptions{};
  return releaseInstanceWithOptions(request, runtime);
}

model RenewInstanceRequest {
  clientToken?: string(name='ClientToken'),
  duration?: int32(name='Duration'),
  instanceId?: string(name='InstanceId'),
  ownerId?: long(name='OwnerId'),
  pricingCycle?: string(name='PricingCycle'),
}

model RenewInstanceResponseBody = {
  orderId?: string(name='OrderId'),
  requestId?: string(name='RequestId'),
}

model RenewInstanceResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: RenewInstanceResponseBody(name='body'),
}

async function renewInstanceWithOptions(request: RenewInstanceRequest, runtime: Util.RuntimeOptions): RenewInstanceResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.clientToken)) {
    query['ClientToken'] = request.clientToken;
  }
  if (!Util.isUnset(request.duration)) {
    query['Duration'] = request.duration;
  }
  if (!Util.isUnset(request.instanceId)) {
    query['InstanceId'] = request.instanceId;
  }
  if (!Util.isUnset(request.ownerId)) {
    query['OwnerId'] = request.ownerId;
  }
  if (!Util.isUnset(request.pricingCycle)) {
    query['PricingCycle'] = request.pricingCycle;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'RenewInstance',
    version = '2016-11-11',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function renewInstance(request: RenewInstanceRequest): RenewInstanceResponse {
  var runtime = new Util.RuntimeOptions{};
  return renewInstanceWithOptions(request, runtime);
}

model UpgradeInstanceRequest {
  clientToken?: string(name='ClientToken'),
  extBandwidth?: int32(name='ExtBandwidth'),
  extDomainPackage?: int32(name='ExtDomainPackage'),
  instanceId?: string(name='InstanceId'),
  ownerId?: long(name='OwnerId'),
  packageCode?: string(name='PackageCode'),
}

model UpgradeInstanceResponseBody = {
  orderId?: string(name='OrderId'),
  requestId?: string(name='RequestId'),
}

model UpgradeInstanceResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: UpgradeInstanceResponseBody(name='body'),
}

async function upgradeInstanceWithOptions(request: UpgradeInstanceRequest, runtime: Util.RuntimeOptions): UpgradeInstanceResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.clientToken)) {
    query['ClientToken'] = request.clientToken;
  }
  if (!Util.isUnset(request.extBandwidth)) {
    query['ExtBandwidth'] = request.extBandwidth;
  }
  if (!Util.isUnset(request.extDomainPackage)) {
    query['ExtDomainPackage'] = request.extDomainPackage;
  }
  if (!Util.isUnset(request.instanceId)) {
    query['InstanceId'] = request.instanceId;
  }
  if (!Util.isUnset(request.ownerId)) {
    query['OwnerId'] = request.ownerId;
  }
  if (!Util.isUnset(request.packageCode)) {
    query['PackageCode'] = request.packageCode;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'UpgradeInstance',
    version = '2016-11-11',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function upgradeInstance(request: UpgradeInstanceRequest): UpgradeInstanceResponse {
  var runtime = new Util.RuntimeOptions{};
  return upgradeInstanceWithOptions(request, runtime);
}

